<!-- 我的 -->
<template>
	<view>
		<view class="user-body">
			<!-- head -->
			<view class="user-head u-flex u-flex-between u-flex-items-center">
				<view class="u-flex u-flex-y-center">
					<view class="m-flex-no u-m-r-20">
						<!-- mpAvatar -->
						<u-avatar :src="userInfo.avatar" size="60"></u-avatar>
					</view>
					<!-- <u-button size="small" :hair-line="false" @click="loginIn" :custom-style="loginStyle"
						v-if="!userInfo.token">授权登录</u-button>
					<u-button size="small" :hair-line="false" @click="obtain = true" :custom-style="loginStyle"
						v-else-if="userInfo.token && !userInfo.mobile">授权手机号</u-button> -->

					<button class="boxbuttom" open-type="getUserInfo" @click="loginIn" v-if="!userInfo.token">授权登录</button>
					<button class="boxbuttom" open-type="getPhoneNumber" @click="obtain = true" v-else-if="userInfo.token && !userInfo.mobile">授权手机号</button>

					<view v-else class="u-flex-1">
						<view class="u-font-32">{{ userInfo.nickname }}</view>
						<!-- <view class="u-font-24 u-m-t-20 user-info">{{ userInfo.status }}</view> -->
						<view class="u-font-24 u-m-t-20 user-info">
							{{userInfo.level==1?'普通用户':userInfo.level==2?'高级用户':'明星用户'}}</view>
					</view>
				</view>
				<view class="u-flex">
					<view class="u-m-l-20 m-flex-y u-flex-items-center" @click="nextNav('/pages/mine/erwei')">
						<u-icon name="fenxiang" customPrefix="master" size="21" color="#fff"></u-icon>
						<view>分享</view>
					</view>
				</view>
			</view>

			<!-- 房贷计算 -->
			<view class="u-p-t-60">
				<u-grid :col="4">
					<u-grid-item v-for="(item, index) in picture" :key="index" @click="nextNav(item.url)">
						<u-icon :name="item.icon" customPrefix="master" size="33" color="#fff"></u-icon>
						<view class="m-c-w u-m-t-20">{{ item.name }}</view>
					</u-grid-item>
				</u-grid>
			</view>
			<!-- 我的客户 -->
			<kefu title="我的客户" :list="recom" :col="4" pathUrl="/pages/mine/kehu"></kefu>

			<!-- 领取 -->
			<!-- <view class="u-rela u-m-t-30">
				<u-image width="100%" height="100" mode="scaleToFill" border-radius="20" :src="oss + '/mine/ling.png'"></u-image>
				<view class="u-abso hongbao">红包金额：68元</view>
			</view> -->
 
			<!-- 奖励 -->
			<kefu title="奖励" :list="jiangli" :col="2" pathUrl="/pages/mine/tixian"></kefu>

			<!-- 我是业主 -->
			<list-item v-if="yezhu[0]" title="我是业主" :paramsObj="yezhu[0]" :btns="yezhuBtns" :type="1"></list-item>

			<!-- 我是租客 -->
			<list-item v-if="zuke[0]" title="我是房东" :paramsObj="zuke[0]" :btns="zukeBtns" :type="2"></list-item>

			<!-- 功能 -->
			<view class="m-card u-rela u-m-t-30">
				<u-cell-group><u-cell size="large" v-for="(item, index) in column" :key="index" :title="item.title" :value="item.value" @click="columnClick(index)"></u-cell></u-cell-group>
				<official-account class="u-abso lifestyle"></official-account>
				<!-- 关注 -->
				<view class="u-flex u-flex-between u-flex-items-center u-m-t-30" @click="nextNav('no')">
					<view class="u-flex u-flex-items-center">
						<u--image width="60" height="60" radius="6" :src="logo"></u--image>
						<view class="list-info u-m-l-20">
							<view class="u-font-24 m-font-b">内当家 - 房产比价APP</view>
							<view class="u-font-24 m-c-9 u-m-t-20">团购省钱 ,现金补贴</view>
						</view>
					</view>
					<view class="xiazai">立即下载</view>
				</view>
			</view>

			<!-- 弹出框 -->
			<tuanyuan ref="tuanyuan"></tuanyuan>
			<u-loading-page loading-text="内当家APP" :loading="pageLoad"></u-loading-page>
			<obtain :show="obtain" @showchange="obtainOk"></obtain>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userInfo: {},
			picture: [
				{
					icon: 'jisuan',
					name: '房贷计算',
					url: '/pages/house_loan_calculator/house_loan_calculator'
				},
				{
					icon: 'wode',
					name: '购房管家',
					url: '/pages/mine/guanjia'
				},
				{
					icon: 'aixin',
					name: '我的粉丝',
					url: '/pages/mine/fensi'
				},
				{
					icon: 'shezhi',
					name: '用户等级',
					url: '/pages/mine/dengji'
				}
			],
			recom: [
				{
					shu: 0,
					name: '已推荐',
					url: '/pages/mine/kehu'
				},
				{
					shu: 0,
					name: '已到访',
					url: '/pages/mine/kehu'
				},
				{
					shu: 0,
					name: '已认购',
					url: '/pages/mine/kehu'
				},
				{
					shu: 0,
					name: '已确认',
					url: '/pages/mine/kehu'
				}
			],
			jiangli: [
				{
					shu: 0,
					name: '可提现',
					url: '/pages/mine/tixian'
				},
				{
					shu: 0,
					name: '实际发放',
					url: 'fafang'
				}
			],
			yezhu: [],
			yezhuBtns: [
				{
					name: '我要买房',
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/s-o.png',
					url: '/pages/handhousing/buyahouse'
				},
				{
					name: '我要出租',
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/r.png',
					url: '/pages/mine/chuzu'
				},
				{
					name: '我的房子',
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/o.png',
					url: '/pages/mine/fangzi?type=1'
				}
			],
			zuke: [],
			zukeBtns: [
				{
					name: '我要买房',
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/s-o.png',
					url: '/pages/handhousing/buyahouse'
				},
				{
					name: '我的出租房',
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/a.png',
					url: '/pages/mine/chuzu?type=0'
				}
			],
			column: [
				{
					title: '关注服务号：',
					value: '内当家APP'
				},
				{
					title: '客服电话：',
					value: '4008089309'
				},
				{
					title: '关于我们：',
					value: ''
				}
			]
		};
	},
	async onShow() {
		let that = this;
		await this.getNew();
		await this.getCustomer();
		let yezhu = await this.require('getHouse', {
			p: 1,
			pnum: this.pnum
		});
		if (yezhu) {
			this.yezhu = yezhu;
		}
		let zuke = await this.require('getLeasehouse', {
			p: 1,
			pnum: this.pnum
		});
		if (zuke) {
			this.zuke = zuke;
		}
		this.pageLoad = false;
		this.xinxiao();
	},
	methods: {
		obtainOk() {
			this.obtain = false;
			this.getNew();
		},
		async login() {
			let userInfo = await this.require('userInfo');
			if (userInfo) {
				uni.setStorageSync('userInfo', JSON.stringify(userInfo));
				uni.setStorageSync('token', userInfo.token);
				uni.setStorageSync('userId', userInfo.id);
				this.userInfo = userInfo;
				if (userInfo.mobile) {
					uni.setStorageSync('mobile', userInfo.mobile);
				}
				this.jiangli[0].shu = userInfo.money || 0;
				this.jiangli[1].shu = userInfo.txmoney || 0;
			}
		},
		async getNew() {
			let token = uni.getStorageSync('token');
			if (token) {
				await this.login();
			}
		},
		async loginIn() {
			let login = await this.getMobile();
			if (login) {
				await this.getNew();
			}
		},
		async getCustomer() {
			//我的客户
			let res = await this.require('getKehunum');
			if (res) {
				for (var i = 0; i < this.recom.length; i++) {
					this.recom[i].shu = res['status' + i];
				}
			}
		},
		columnClick(e) {
			console.log(e);
			switch (e) {
				case 0:
					break;
				case 1:
					uni.makePhoneCall({
						phoneNumber: '4008089309'
					});
					break;
				case 2:
					this.nextNav('/pages/mine/about');
					break;
				default:
					break;
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.user-body {
	min-height: 100vh;
	background: linear-gradient(#0e5642, rgba(14, 86, 66, 0.65) 30%, #f6f5f5 45%, #f1f1f1 100%);
	padding: 30rpx;
}

.user-head {
	margin-top: 120rpx;
	color: #fff;
}

.user-info {
	display: inline-block;
	padding: 0 20rpx;
	background-color: #d37a38;
	border-radius: 100rpx;
	height: 40rpx;
	line-height: 40rpx;
}

.hongbao {
	right: 40rpx;
	top: 30rpx;
	color: #fff;
	font-size: 42rpx;
}

.lifestyle {
	width: 100%;
	height: 100rpx;
	top: 20rpx;
	left: 20rpx;
	right: 20rpx;
	opacity: 0;
}

.xiazai {
	width: 200rpx;
	height: 70rpx;
	line-height: 70rpx;
	background-color: #d37a38;
	border-radius: 40rpx;
	font-size: 32rpx;
	font-weight: bold;
	color: #fff;
	text-align: center;
}
</style>
